package com.ruoyi.api.controller.addons;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.api.service.ShoproServer;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.weixin.shop.domain.YxStoreCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author anan.
 * @version 1.0
 * @create 2021-07-08 10-51
 */
@RestController
@RequestMapping("/addons/shopro")
public class ShoproController {

	@Autowired
	private ShoproServer shoproServer;

	/**
	 * 初始化数据
	 * @return
	 */
	@GetMapping("/index/init")
	public AjaxResult init(){
		return AjaxResult.success("初始化数据",shoproServer.getInit());
	}

	/**
	 * 同步后端路由 具体做了什么操作，目前不清楚
	 * @return
	 */
	@PostMapping("/index/asyncPages")
	public AjaxResult asyncPages(){
		return AjaxResult.success("");
	}

	/**
	 * 优惠券列表
	 * @param
	 * @return
	 */
	@GetMapping("/coupons/lists")
	public AjaxResult couponsLists(@RequestParam String ids){
		return AjaxResult.success("优惠券列表", shoproServer.getCouponsLists(ids));
	}

	/**
	 * 商品列表
	 * @param
	 * @return
	 */
	@GetMapping("/goods/lists")
	public AjaxResult goodsLists(@RequestParam String category_id,@RequestParam String page){
		return AjaxResult.success("商品列表",shoproServer.getGoodsLists(category_id,page));
	}

	/**
	 * 活动列表
	 * @param
	 * @return
	 */
	@GetMapping("/goods/activity")
	public AjaxResult goodsActivity(@RequestParam(required = false) String activity_id,
									@RequestParam(required = false) String need_buyer){
		if (need_buyer==null) {
			// 秒杀
			return AjaxResult.success("活动列表",shoproServer.getGoodsActivity1(activity_id));
		}else{
			// 拼团
			return AjaxResult.success("活动列表",shoproServer.getGoodsActivity2(activity_id,need_buyer));
		}
	}

	/**
	 * 返回模板信息
	 * @param shop_id
	 * @return
	 */
	@GetMapping("/index/template")
	public AjaxResult template(@RequestParam String shop_id){
//		JSONObject jsonObject = new JSONObject();
//		// 悬浮按钮
//		jsonObject.put("float-button", shoproServer.getFloatButton());
//		// 轮播、菜单 、优惠券、拉黑、秒杀、广告魔方、分类选项卡
//		jsonObject.put("home", shoproServer.getHome());
//		// 弹窗提醒
//		jsonObject.put("popup", shoproServer.getPopup());
//		// 底部导航
//		jsonObject.put("tabbar", shoproServer.getTabbar());
//		// 用户卡片
//		jsonObject.put("user", shoproServer.getUser());
//		return AjaxResult.success("模板数据",jsonObject);

		return AjaxResult.success("模板数据",shoproServer.getTemplate());
	}

	@PostMapping("user/getWxMiniProgramSessionKey")
	public AjaxResult getWxMiniProgramSessionKey(@RequestBody Map map){
		return AjaxResult.wraning("未获取session_key,请重启应用",null);
	}

}
